package org.rsbot.script.internal.wrappers;

public class HashTable {
	private final org.rsbot.client.HashTable hashTable;
	private org.rsbot.client.Node current;
	private int c_index = 0;

	public HashTable(final org.rsbot.client.HashTable hashTable) {
		this.hashTable = hashTable;
	}

	public org.rsbot.client.Node getFirst() {
		c_index = 0;
		return getNext();
	}

	public org.rsbot.client.Node getNext() {
		if (c_index > 0 && hashTable.getBuckets()[c_index - 1] != current) {
			final org.rsbot.client.Node node = current;
			current = node.getPrevious();
			return node;
		}
		while (c_index < hashTable.getBuckets().length) {
			final org.rsbot.client.Node node = hashTable.getBuckets()[c_index++].getPrevious();
			if (hashTable.getBuckets()[c_index - 1] != node) {
				current = node.getPrevious();
				return node;
			}
		}
		return null;
	}
}